# include <stdlib.h>
# include <unistd.h>
# include <stdio.h>
# include <curses.h>
# include "structures.h"
# include "font.h"
# include "debug.h"


void			debug_display_ba(value		ba)
{
  int			*p;
  int			x, y;
  p_context		c;

  p = Data_bigarray_val(ba);
  c = p[IBA_CONTEXT];

  wmove(stdscr, 0, 0);
  mvwprintw(stdscr, 0, 0, "BA_CONTENT");

  mvwprintw(stdscr, 1, 0, "IBA_VID_NBCHAR_WIDTH %i", p[IBA_VID_NBCHAR_WIDTH]);
  mvwprintw(stdscr, 2, 0, "IBA_VID_NBCHAR_HEIGHT %i", p[IBA_VID_NBCHAR_HEIGHT]);

  mvwprintw(stdscr, 3, 0, "IBA_SCREEN_LINE %i", p[IBA_SCREEN_LINE]);
  mvwprintw(stdscr, 4, 0, "IBA_SCREEN_COL %i", p[IBA_SCREEN_COL]);

  mvwprintw(stdscr, 5, 0, "IBA_VIDEO_LINE %i", p[IBA_VIDEO_LINE]);
  mvwprintw(stdscr, 6, 0, "IBA_VIDEO_COL %i", p[IBA_VIDEO_COL]);

  getmaxyx(stdscr, x, y);
  mvwprintw(stdscr, 8, 0, "Screen Size shd be : %i, %i\n", x, y);
  getmaxyx(WVIDEO, x, y);
  mvwprintw(stdscr, 9, 0, "Video Size shd be : %i, %i\n", x, y);

  wrefresh(stdscr);
  debug_pause();
  /* debug_quit(); */
}


void			debug_dispkey(void)
{
  int			ch = 0;

  nodelay(stdscr, false);
  ch = getch();
  printw("Key pressed : ");
  attron(A_BOLD);
  printw("%c", ch);
  attroff(A_BOLD);
  getch();
}


void			debug_display_alpha(void)
{
  waddstr(stdscr, FONT_A);
  waddstr(stdscr, FONT_B);
  waddstr(stdscr, FONT_C);
  waddstr(stdscr, FONT_D);
  waddstr(stdscr, FONT_E);
  debug_pause();
  clear();
  move(0, 0);

  waddstr(stdscr, FONT_F);
  waddstr(stdscr, FONT_G);
  waddstr(stdscr, FONT_H);
  waddstr(stdscr, FONT_I);
  waddstr(stdscr, FONT_J);
  debug_pause();
  clear();
  move(0, 0);

  waddstr(stdscr, FONT_K);
  waddstr(stdscr, FONT_L);
  waddstr(stdscr, FONT_M);
  waddstr(stdscr, FONT_N);
  waddstr(stdscr, FONT_O);
  debug_pause();
  clear();
  move(0, 0);

  waddstr(stdscr, FONT_P);
  waddstr(stdscr, FONT_Q);
  waddstr(stdscr, FONT_R);
  waddstr(stdscr, FONT_S);
  waddstr(stdscr, FONT_T);
  debug_pause();
  clear();
  move(0, 0);

  waddstr(stdscr, FONT_U);
  waddstr(stdscr, FONT_V);
  waddstr(stdscr, FONT_W);
  waddstr(stdscr, FONT_X);
  waddstr(stdscr, FONT_Y);
  debug_pause();
  clear();
  move(0, 0);

  waddstr(stdscr, FONT_Z);
  waddstr(stdscr, FONT_QM);
  waddstr(stdscr, FONT_EM);
  waddstr(stdscr, FONT_COMA);
  waddstr(stdscr, FONT_SHARP);
  waddstr(stdscr, FONT_DOT);
  debug_pause();
  clear();
}


void			debug_display_frame(WINDOW	*w)
{
  wborder(w, 'G', 'D', 'H', 'B',
  	  ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER);
}



int			debug_drawone(p_context		c)
{
  WINDOW	*w;
  int		line, col;
  int		offset = 0;
  int		i, j;

  w = c->win[ZONE_MAIN]; /* grepme */
  getmaxyx(w, line, col);
  wmove(w, 0, 0);
  waddch(w, 'a' + offset); /* last char */

  for (i = 0; i < line; i++)
  {
    for (j = 0; j < col; j++)
    {
      offset = (rand() % 26);
      mvwaddch(w, i, j, 'a' + offset);
      wgetch(w);
    }
  wrefresh(w);
  }

  return (0);
}


void			debug_quit(void)
{
  endwin();
  exit(-1);
}


void			debug_pause(void)
{
  nodelay(stdscr, false);
  getch();
  nodelay(stdscr, true);
}


void			debug_pp(void)
{
  clear();
  wprintw(stdscr, "DEBUG\n");
  wprintw(stdscr, "debug\n");
  wprintw(stdscr, "azert\n");
  wprintw(stdscr, "qwert\n");
  wprintw(stdscr, "lol\n");
  refresh();
  debug_pause();
}
